#!groovy
pipeline {
    agent any

    environment{
        REPOSITORY="http://192.168.0.223:2019/root/maynrent-cloud.git"
        PROJECT="maynrent-cloud"
        SCRIPT_PATH="/root/jenkins/scripts/maynrent-cloud"
        MODULE_PATH=""
        MODULE_NAME=""
    }
    stages {
        stage('获取代码') {
            steps {
                echo "start fetch code from gitlab:${REPOSITORY}"
                deleteDir()
                git branch: 'test', url: "${REPOSITORY}"
            }
        }

        stage('编译') {
            steps {
                echo "start compile"
                sh "mvn -f pom.xml clean package -U -pl ${MODULE_PATH}/${MODULE_NAME} -am -P test -Dmaven.test.skip=true"
            }
        }
        
        stage('构建镜像') {
            steps {
                echo "start build images"
                sh "${SCRIPT_PATH}/${PROJECT}-build-one.sh  ${PROJECT} ${MODULE_PATH} ${MODULE_NAME} ${SCRIPT_PATH}"
            }
        }
        
        stage('发布系统') {
            steps {
                echo "start deploy ${PROJECT} system"
                sh "${SCRIPT_PATH}/${PROJECT}-deploy-one.sh ${SCRIPT_PATH} kube-${PROJECT} ${MODULE_NAME}"
            }
        }
    }
}